package com.leihub.xlfiletools.html.pojo;

import com.leihub.xlfiletools.html.annotation.DisplayField;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.Duration;
import java.time.LocalDateTime;

@Getter
@Setter
@ToString
public class BatchProcess {

    @DisplayField(name = "Pre-Start Time", group = 1, groupName = "Pre-Processing")
    private LocalDateTime preStartTime;

    @DisplayField(name = "Pre-End Time", group = 1, groupName = "Pre-Processing")
    private LocalDateTime preEndTime;

    @DisplayField(name = "Pre-Duration", group = 1, groupName = "Pre-Processing")
    private String  preDuration;

    @DisplayField(name = "Mid-Start Time", group = 2, groupName = "Mid-Processing")
    private LocalDateTime midStartTime;

    @DisplayField(name = "Mid-End Time", group = 2, groupName = "Mid-Processing")
    private LocalDateTime midEndTime;

    @DisplayField(name = "Mid-Duration", group = 2, groupName = "Mid-Processing")
    private String  midDuration;

    @DisplayField(name = "Post-Start Time", group = 3, groupName = "Post-Processing")
    private LocalDateTime postStartTime;

    @DisplayField(name = "Post-End Time", group = 3, groupName = "Post-Processing")
    private LocalDateTime postEndTime;

    @DisplayField(name = "Post-Duration", group = 3, groupName = "Post-Processing")
    private String  postDuration;

    public BatchProcess(LocalDateTime preStartTime, LocalDateTime preEndTime,
                        LocalDateTime midStartTime, LocalDateTime midEndTime,
                        LocalDateTime postStartTime, LocalDateTime postEndTime) {
        this.preStartTime = preStartTime;
        this.preEndTime = preEndTime;
        this.preDuration = calculateDuration(preStartTime, preEndTime);

        this.midStartTime = midStartTime;
        this.midEndTime = midEndTime;
        this.midDuration = calculateDuration(midStartTime, midEndTime);

        this.postStartTime = postStartTime;
        this.postEndTime = postEndTime;
        this.postDuration = calculateDuration(postStartTime, postEndTime);
    }

    private String calculateDuration(LocalDateTime startTime, LocalDateTime endTime) {
        Duration duration = Duration.between(startTime, endTime);
        long hours = duration.toHours();
        long minutes = duration.toMinutesPart();
        return String.format("%d hours %d minutes", hours, minutes);
    }
}
